package com.wei.myhame.Adapter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wei.myhame.R;
import com.wei.myhame.model.bean.VisitmattersBean;

import java.util.ArrayList;
import java.util.List;

public class Recy_Adapter extends RecyclerView.Adapter<Recy_Adapter.Holder> {

    List<VisitmattersBean.DataBean.ListBean> list;
    Context context;


    public Recy_Adapter(List<VisitmattersBean.DataBean.ListBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item, null);
        return new Holder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        holder.editText.setText(list.get(position).getServiceTypeName());
        //焦点选中时放大，失去焦点后还原：
        holder.itemView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    holder.itemView.animate().scaleX(1.05f).scaleY(1.2f).setDuration(300).start();
                } else {
                    holder.itemView.animate().scaleX(1.0f).scaleY(1.0f).setDuration(300).start();
                }
            }
        });



    }

    @Override

    public int getItemCount() {
        return list.size();
    }

    public class Holder extends RecyclerView.ViewHolder{
        int i=0;
        EditText editText;
        List<EditText>elist=new ArrayList<>();
        public Holder(@NonNull final View itemView) {
            super(itemView);
            editText=itemView.findViewById(R.id.edits);
            editText.setCursorVisible(false);//隐藏光标
            editText.setFocusable(true);
            //当前视图是否是焦点视图
            editText.isFocused();
          //  当前视图或者其子视图是否含有焦点–
            editText.hasFocus();
         //   editText.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS)
            //实现点击一次就监听的效果
            editText.setOnTouchListener(new View.OnTouchListener() {
                //按住和松开的标识
                int touch_flag=0;
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    touch_flag++;
                    if(touch_flag==2){
                        touch_flag=0;
                        //自己的业务
                        editText.setVisibility(View.VISIBLE);
                        Log.i("SS", "onTouch: "+editText.getText());
                        editText.setFocusable(true);
                        editText.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                editText.setFocusable(true);
                            }
                        });
                    } return false; }
            });

        }
    }


}
